<template>
  <div class="agentList">
    <search class="search" :searchInfo="searchInfo" @search="init"></search>
    <div class="agent-list" v-show="lists.length>0">
      <div style="display: none;">{{random_content}}</div>
      <van-list
        v-model="loading"
        :finished="finished"
        :immediate-check='immediateCheck'
        :error.sync="error"
        error-text="请求失败，点击重新加载"
        finished-text=""
        @load="onLoad"
      >
        <div v-for="(item, index) in lists" :key="index" class="list">
          <div class="share_times">
            <a href="javascript:;" @click="openLink(item.link)">
              <img :src="item.view_pic || defaultImg" alt />
            </a>
          </div>
          <div class="share_title">
            <div class="title_box">
              <span class="maintitle">
                <a href="javascript:;" @click="openLink(item.link)" v-html="item.title"></a>
              </span>
              <span class="read-num">
                <a href="javascript:;" @click="openLink(item.link)" class="link">
                  <img class="read" mode="scaleToFill" src="https://img.wifenxiao.com/h5-wfx/images/user/read.png" alt />
                  <span>{{item.pv_num}}</span>
                </a>
              </span>
            </div>
            <p class="excerpt" v-if="item.excerpt">
              <!-- <img class="fl" :src="excerptStarImg" alt /> -->
              <span class="subtitle fl" v-html="item.excerpt"></span>
            </p>
          </div>
        </div>
      </van-list>
    </div>
    <!-- 与 H5 保持一致 -->
    <!-- <div class="no-data-box" v-show="!lists.length && finished">
      <no-data :noData="noData"></no-data>
    </div> -->
    <div class="fx-sum-get fulltext" v-if="content" v-html="content"></div>
  </div>
</template>

<script>
import Vue from 'vue'
import { openPage } from '@/utils/utils'
import noData from '@/components/noData/index'
import Search from '@/components/Search/index'
import { getAgentList } from '@/api/user/fxs/fxsApi'

export default Vue.extend({
  components: {
    Search,
    noData
    // searchBox
  },
  data() {
    return {
      noData: {
        text: '暂无数据',
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no-data.png',
        width: '214px',
        marginTop: '60px',
        txtMarginTop: '-30px'
      },
      searchInfo: {
        placeholder: '请输入标题关键字'
      },
      img: 'http://mp.wfx.qibcms.com/Public/images/diy/waitupload.png',
      defaultImg:'https://img.wifenxiao.com/h5-wfx/images/default_goods_img2.jpg',
      // excerptStarImg,
      Placeholder: '请输入标题关键字',
      // showClose: true,
      // iconSearch: false,
      // word: '',

      random_content: '',
      lists: [],
      content: '',
      listParams: {
        p: 1,
        title: ''
      },
      loading: false,
      error: false,
      finished: false,
      immediateCheck: false
    }
  },
  created() {
    this.init()
    // console.log('不是分销商进入,需要处理')
  },
  methods: {
    openLink(link){
      openPage(link)
    },
    init(keyword) {
      this.listParams.p = 1
      this.listParams.title = keyword
      this.lists=[]
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 50000)
      getAgentList(this.listParams).then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
            wx.setNavigationBarTitle({
              title: res.data.ftitle_magazine
            })
          
          this.random_content = res.data.random_content
          if(res.data.list && res.data.list.length){
            this.lists = res.data.list
            this.listParams.p++
          }else{
            this.finished = true
          }
          this.content = res.data.content
        } else {
          this.$Error(res.msg)
        }
      })
    },
    onLoad(keyword) {
      getAgentList(this.listParams).then(res => {
        this.loading = false
        if (res.status == 1) {
          if (res.data && res.data.length) {
            this.lists.push(...res.data)
            this.listParams.p++
          } else {
            this.finished = true
          }
        } else {
          this.$Error(res.msg)
        }
      }).catch(() => {
        this.error = true
      })
    },
    onItemClick(id) {
      this.$JumpPath(this, 'magazine', {
        'magazine_id': id
      })
    }
  },
  mounted() {
    // 小程序触底加载更多
    window.addEventListener('reachbottom', () => {
      this.onLoad()
    })
  }
})
</script>

<style lang="scss">
@import 'src/styles/variables';
@import 'src/styles/mixin';
.agentList {
  .search {
    padding: 30px 24px;
    border-radius:0px 0px 20px 20px;
    background: $default;
  }
  .agent-list {
    // width: 100%;
    margin: 20px 24px;
    height: auto;
    .list {
      width: 100%;
      background-color: #fbfbfb;
      margin-bottom: 20px;
      border-radius: 20px;
      overflow: hidden;
      box-shadow:0 2px 20px rgba(0,0,0,.04);
      .share_times {
        a {
          img {
            display:block;
            width: 100%;
            max-height:350px;
            object-fit: cover;
          }
        }
      }
      .share_title {
        padding: 24px 24px 30px;
        .title_box{
          display: flex;
          justify-content: space-between;
          align-items: center;
          // flex-direction: column;
        }
        .maintitle {
          font-size: 32px;
          line-height:1.3;
          max-width:85%;
          font-weight: bold;
          @include showEllipsis;
        }
        .read-num {
          color: #666;
          .link {
            display: flex;
            justify-content: center;
            align-items: center;
            .read {
              width: 30px;
              height: 20px;
              margin-right: 8px;
            }
            span {
              height: 26px;
              font-size: 24px;
              vertical-align: middle;
            }
          }
        }

        .excerpt {
          font-size: 26px;
          color: #666;
          margin-top: 12px;
          display: flex;
          align-items: center;
          img {
            width: 30px;
            height: 30px;
          }
          .subtitle {
            // font-family: miui;
            width: 90%;
            height: 30px;
            @include showEllipsis;
            color: #666;
            font-size: 26px;
          }
        }
      }
    }
  }
}
</style>
